package Servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import anonymus.excepcion.DAOExcepcion;
import anonymus.negocio.UsuarioNegocio;

/**
 * Servlet implementation class RegistroPersonaServlet
 */
@WebServlet("/RegistroPersonaServlet")
public class RegistroPersonaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegistroPersonaServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	
		UsuarioNegocio neg = new UsuarioNegocio();
		
		int tipoUsuario  =Integer.parseInt(request.getParameter("cboTipoUsuario"));
		String nombre = request.getParameter("txtNombre");
		String paterno = request.getParameter("txtPaterno");
		String materno = request.getParameter("txtMaterno");
		int sex  =Integer.parseInt(request.getParameter("cbosexo"));
				String sexo = "";
					if (sex == 0)
						sexo = "Masculino";
					else if (sex == 1)
						sexo = "Femenino";
		int tipoDoc  =Integer.parseInt(request.getParameter("cboTipoDocumento"));			
				String tipoDocumento = "";
					if (tipoDoc == 0)
						tipoDocumento = "DNI";
					else if (tipoDoc == 1)
						tipoDocumento = "Pasaporte";
					else if (tipoDoc == 2)
						tipoDocumento = "Carnet de Extrangeria";
		
		String documento = request.getParameter("txtDocumento");
				int doc = Integer.parseInt(documento);
		String correo = request.getParameter("txtCorreo");
		String clave = request.getParameter("txtClave");
		String fecha = request.getParameter("txtDia");
		String telefono = request.getParameter("txtCelular");
				
		
			 System.out.println("Grabado Satisfactoriamente");
             try {
                     neg.insertarUsuario(nombre, paterno, materno, sexo, tipoDocumento, doc, fecha, telefono, tipoUsuario, correo, clave);
         			RequestDispatcher rd=request.getRequestDispatcher("/Ingreso.jsp");
        			rd.forward(request, response);
                    
             } catch (DAOExcepcion e) {
                     // TODO Auto-generated catch block
                     e.printStackTrace();
		
             }
	}
}
